﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ControlUser_ControlChotNVDieuChinhTonKho : System.Web.UI.UserControl
{
    string error = "";

    ClassExecute.ClassExecute dt;
    string str = BCDataCenter.Configuration.CurrentConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetWorkingDay();
            BindGrid();
        }
    }
    void GetWorkingDay()
    {
        dt = new ClassExecute.ClassExecute();
        DataTable db = dt.Get_Data_DataTable(str, ref error, "get_location", CommandType.StoredProcedure,
            new SqlParameter("@sitecode", Session["sitecode"].ToString()));
        string DocDate = dt.GetDataDepend(str, "ls_getWorkingDay", CommandType.StoredProcedure, ref error,
            new SqlParameter("@Location",db.Rows[0]["location"].ToString()));
        LitDate.Text = DocDate;
        LitPP.Text = db.Rows[0]["description"].ToString();

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            dt = new ClassExecute.ClassExecute();
            GridViewRow grv = ((Control)e.CommandSource).NamingContainer as GridViewRow;
            bool kq = dt.ExecuteSQl_bool(str, CommandType.StoredProcedure, "ls_postAdjTrn", ref error,
                new SqlParameter("@docno", grv.Cells[0].Text));
            if (kq)
            {
                uscMsgBox1.AddMessage("Nghiệp vụ chốt điều chỉnh tồn kho thành công", uscMsgBox.enmMessageType.Success);
                BindGrid();
            }
            else
            {
                uscMsgBox1.AddMessage("Nghiệp vụ chốt điều chỉnh tồn kho thất bại", uscMsgBox.enmMessageType.Success);
            }
            
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindGrid();
    }
    void BindGrid()
    {
        dt = new ClassExecute.ClassExecute();
        GridView1.DataSource = null;
        DataTable db = dt.Get_Data_DataTable(str, ref error, "ls_getAdjTrnNoList4Post", CommandType.StoredProcedure,
            new SqlParameter("@siteCode", Session["sitecode"].ToString()));
        if (db.Rows.Count > 0)
        {
            GridView1.DataSource = db;
            
        }
        GridView1.DataBind();
    }
}